/**
 * 日期工具类
 */

/**
 * 输入时间戳，输出格式化串  1559095947890 -> 2019-05-29 10:12:27 
 * 
 */
export const formatTimeToStr = (time) => {
    let date = new Date(time);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let m = date.getMinutes();
    m = m < 10 ? ('0' + m) : m;
    let s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
}

/**
 * 输入时间戳，输出格式化串  1559095947890 -> 2019-05-01
 * 
 */
export const formatTimeToDate = (time) => {
    let date = new Date(time);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    return y + '-' + MM + '-' + d;
}

/**
 *  输入时间戳，输出格式化串  1559095947890 -> 20190501
 * 
 */
export const formatTimeToYearMonthDay = (time) => {
    let date = new Date(time);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    return y + '' + MM + '' + d;
}

/**
 *  输入时间戳，输出格式化串  1559095947890 -> 201905
 * 
 */
export const formatTimeToYearMonth = (time) => {
    let date = new Date(time);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    return y + '' + MM;
}

/**
 *  输入时间戳，输出格式化串  1559095947890 -> 2019
 * 
 */
export const formatTimeToYear = (time) => {
    let date = new Date(time);
    let y = date.getFullYear();
    return y;
}

/**
 *  获取当前日期，类似 2019-01-01 11:11:11
 * 
 */
export const getCurrentDateTime = () => {
    let date = new Date();
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let m = date.getMinutes();
    m = m < 10 ? ('0' + m) : m;
    let s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
}

/**
 * 获取当前日期 2019-01-01 
 * 
 */
export const getCurrentDate = () => {
    let date = new Date();
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    return y + '-' + MM + '-' + d;
}

/**
 * 获取当前日期 20190101 
 * 
 */
export const getCurrentShortDate = () => {
    let date = new Date();
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    return y + '' + MM + '' + d;
}

/**
 * 获取当前时间 dd:mm:ss 
 * 
 */
export const getCurrentTime = () => {
    let date = new Date();
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let m = date.getMinutes();
    m = m < 10 ? ('0' + m) : m;
    let s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    return h + ':' + m + ':' + s;
}

/**
 * 获取当前年度 yyyy
 * 
 */
export const getCurrentYear = () => {
    let date = new Date();
    return date.getFullYear();
}

/**
 * 获取当前月份 mm 
 * 
 */
export const getCurrentMonth = () => {
    let date = new Date();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    return MM;
}